<template>
	<view class="back-top" v-show="isShow" @click="toTop">
		<image class="back-top-img"
			src="https://cdn-cos-ke.myoed.com/ke_proj/mobilev2/m-core/03de0936a7aafee76646b8b2d5fa5b4f.png" mode="">
		</image>
	</view>
</template>

<script setup lang="ts">
import { onLoad } from '@dcloudio/uni-app';
import { ref } from 'vue'
const isShow = ref(false)

onLoad(() => {
	uni.$on('pageScroll', (scrollTop) => {
		if (scrollTop > 300) {
			isShow.value = true
		} else {
			isShow.value = false
		}
	})
})

//返回顶部
const toTop = () => {
	uni.pageScrollTo({
		scrollTop: 0
	})
}
</script>

<style lang="less">
.back-top {
	width: 100upx;
	height: 100upx;
	position: fixed;
	right: 50upx;
	color: red;
	bottom: 20upx;

	.back-top-img {
		width: 100%;
		height: 100%;
	}
}
</style>